/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, {Component} from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    Image,

} from 'react-native';

import {registerApp,pay} from 'react-native-wechat';

import Login from './app/pages/login/Login';
import {Navigator, Tab} from "./app/base/Navigation";
import BaseComponent, {base} from './app/base/Base' ;
let {
    KEY_IS_LOGIN,
    USER_INFO,
    APP_ID_DEBUG,
} = base.fields;
let {
    N004_USERS$_GET_USER,
} = base.requests;

export default class ShoppingDD extends Component {
    constructor(props) {
        super(props);
        this.state = {
            logined: false,
            isLoadingOk: false,//加载中的状态

        }

        //联网获取当前用户登陆状况

        this._checkUserInfo();

    };

    componentDidMount(){
        registerApp(APP_ID_DEBUG)
            .then(succ=>{
                // alert('registerApp succ:'+JSON.stringify(succ))
            })
            .catch(error=>{
                // alert('registerApp error:'+error)
            })
            .done();

    }
    _checkUserInfo() {
        base.network.getUipData(N004_USERS$_GET_USER, '', (success) => {
                this.setState({logined: true, isLoadingOk: true,})
            },
            (error) => {
                this.setState({logined: false, isLoadingOk: true,})
            }
        )
    }

    render() {
        if (this.state.isLoadingOk) {
            if (this.state.logined) {
                return (
                    <Navigator root = {this} />
                );
            } else {
                return (
                    <Login root = {this}/>
                );
            }
        } else {
            return (
                <Image style={{width: '100%', height: '100%'}} source={require('./app/imgs/screen_splash.jpg')}/>
            );
        }


    }
}

AppRegistry.registerComponent('ShoppingDD', () => ShoppingDD);


